const express = require('express');
const router = express.Router();
const permissionController = require('../controllers/permissionController');

/**
 * @swagger
 * tags:
 *   name: 权限管理
 *   description: 管理角色对应的访问权限
 */

/**
 * @swagger
 * /api/permissions:
 *   post:
 *     summary: 创建新的权限记录
 *     tags: [权限管理]
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               role:
 *                 type: integer
 *                 example: 1
 *               name:
 *                  type: string
 *                  example: admin
 *               permission:
 *                 type: array
 *                 items:
 *                   type: string
 *                 example: ["/api/suppliers", "/api/projects"]
 *               description:
 *                 type: string
 *                 example: 管理员权限
 *     responses:
 *       200:
 *         description: 创建成功
 *       500:
 *         description: 服务器错误
 */
router.post('/', permissionController.create);

/**
 * @swagger
 * /api/permissions:
 *   get:
 *     summary: 获取所有权限记录
 *     tags: [权限管理]
 *     responses:
 *       200:
 *         description: 返回所有权限记录
 *       500:
 *         description: 服务器错误
 */
router.get('/', permissionController.getAll);

/**
 * @swagger
 * /api/permissions/{id}:
 *   get:
 *     summary: 根据 ID 获取权限详情
 *     tags: [权限管理]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *     responses:
 *       200:
 *         description: 成功返回权限信息
 *       404:
 *         description: 未找到
 */
router.get('/:id', permissionController.getById);

/**
 * @swagger
 * /api/permissions/{id}:
 *   put:
 *     summary: 更新权限信息
 *     tags: [权限管理]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               role:
 *                 type: integer
 *                name:
 *                  type: string
 *               permission:
 *                 type: array
 *                 items:
 *                   type: string
 *               description:
 *                 type: string
 *               status:
 *                 type: integer
 *     responses:
 *       200:
 *         description: 更新成功
 *       404:
 *         description: 记录不存在
 */
router.put('/:id', permissionController.update);

/**
 * @swagger
 * /api/permissions/{id}:
 *   delete:
 *     summary: 删除权限记录（软删除）
 *     tags: [权限管理]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *     responses:
 *       200:
 *         description: 删除成功
 *       404:
 *         description: 记录不存在
 */
router.delete('/:id', permissionController.delete);

module.exports = router;
